Going to Map Rs's onto BGC2 Cats.
In [15]:
from os.path import join
from csv import DictReader, DictWriter
In [16]:
fieldnames = '#ID DescID M200b Vmax Vrms R200b Rs Np X Y Z VX VY VZ Parent_ID'.split(' ')
In [17]:
missed_keys = dict()
cosmo_idx = 0
halodir = '/u/ki/swmclau2/des/NewAemulusBoxes/Box%03d/halos/m200b/'%cosmo_idx
#halodir = '/home/users/swmclau2/scratch/NewTrainingBoxes/Box%03d/halos/m200b/'%cosmo_idx
#halodir = '/home/users/swmclau2/scratch/TrainingBoxes/Box000/halos/m200b/'
#halodir = '/home/users/swmclau2/scratch/TestBoxes/TestBox000-000/halos/m200b/'
#for snapshot_idx in xrange(10):
snapshot_idx = 2
outlist_fname = join(halodir, "out_%d.list"%snapshot_idx)
bgc2list_fname = join(halodir, "outbgc2_%d.list"%snapshot_idx)
bgc2list_fname2 = join(halodir, "outbgc2_rs_%d.list"%snapshot_idx)
print (cosmo_idx, snapshot_idx),
outlist_idxs = set()
with open(outlist_fname) as csvfile:
reader = DictReader(filter(lambda row: row[0]!='#' or row[:3]=='#ID', csvfile), delimiter = ' ')
for row in reader:
#outlist_rs[row['#ID']] = row['Rs']
outlist_idxs.add(int(row['#ID']))
bgc2_idxs = set()
with open(bgc2list_fname) as oldfile, open(bgc2list_fname2, 'r') as newfile:
reader = DictReader(filter(lambda row: row[0]!='#' or row[:3]=='#ID', newfile), delimiter = ' ')
#writer = DictWriter(newfile, fieldnames, delimiter = ' ')
#writer.writeheader()
for row in reader:
bgc2_idxs.add(int(row['#ID']) )
#try:
# row['Rs'] = outlist_rs[row['#ID']]
#except KeyError:
# missed_keys[cosmo_idx] = row['#ID']
#writer.writerow(row)
print len(bgc2_idxs - outlist_idxs), len(outlist_idxs - bgc2_idxs)
In [18]:
print bgc2_idxs - outlist_idxs
In [19]:
bgc2list_rs = dict()
bgc2_zero_rs = set()
with open(bgc2list_fname2) as csvfile:
reader = DictReader(filter(lambda row: row[0]!='#' or row[:3]=='#ID', csvfile), delimiter = ' ')
for row in reader:
bgc2list_rs[int(row['#ID'])] = float(row['Rs'])
if float(row['Rs']) <= 0:
bgc2_zero_rs.add(int(row['#ID']) )
#print row
print len(zero_rs)
In [20]:
outlist_rs = dict()
outlist_zero_rs = set()
with open(outlist_fname) as csvfile:
reader = DictReader(filter(lambda row: row[0]!='#' or row[:3]=='#ID', csvfile), delimiter = ' ')
for row in reader:
outlist_rs[int(row['#ID'])] = float(row['Rs'])
if float(row['Rs']) <= 0:
outlist_zero_rs.add(int(row['#ID']) )
#print row
print len(zero_rs)
In [21]:
outlist_counter = 0
bgc2_counter = 0
for key in outlist_zero_rs:
if key in outlist_idxs:
outlist_counter+=1
if key in bgc2_idxs:
bgc2_counter+=1
print outlist_counter, bgc2_counter
In [22]:
print_counter = 0
for idx, rs in outlist_rs.iteritems():
if rs == 0:
print idx,
print_counter+=1
if print_counter > 50:
break
In [23]:
outlist_counter = 0
bgc2_counter = 0
for key in bgc2_zero_rs:
if key in outlist_idxs:
outlist_counter+=1
if key in bgc2_idxs:
bgc2_counter+=1
print outlist_counter, bgc2_counter
In [24]:
for key in zero_rs
In [ ]:
outlist_rs.values()
In [ ]:
import numpy as np
rs_arr = np.array(list(outlist_rs.itervalues())).astype(float)
In [ ]:
from matplotlib import pyplot as plt
%matplotlib inline
In [ ]:
n_zero_rs = np.sum(rs_arr == 0)
print n_zero_rs, n_zero_rs*1.0/rs_arr.shape[0]
In [ ]:
plt.hist(rs_arr)
In [ ]: